package com.rslai.base.tool.servertest.intercept;

import com.rslai.base.tool.servertest.command.StepCommand;
import com.rslai.base.tool.servertest.context.Context;
import com.rslai.base.tool.servertest.response.Response;

import java.util.ArrayList;
import java.util.List;

public class InterceptorFactory {
    static List<Interceptor> interceptors = new ArrayList();

    static InterceptorFactory factory = new InterceptorFactory();

    public static void registerInterceptor(Interceptor interceptor) {
        interceptors.add(interceptor);
    }

    public void doBefore(StepCommand command, Response response, Context context) {
        for (Interceptor interceptor : interceptors)
            interceptor.beforeExecute(command, response, context);
    }

    public void doAfter(StepCommand command, Response response, Context context) {
        for (Interceptor interceptor : interceptors)
            interceptor.afterExecute(command, response, context);
    }

    public static InterceptorFactory getInstance() {
        return factory;
    }

    static {
        registerInterceptor(new HttpCallBackInterceptor());
        registerInterceptor(new RestfulApiInterceptor());
        registerInterceptor(new ParamIgnoreInterceptor());
        registerInterceptor(new UploadFileInterceptor());
    }
}
